package com.dongzili.easysearch.custom.controller;

import com.dongzili.easysearch.common.es.EsUtils;
import com.dongzili.easysearch.common.vo.R;
import com.dongzili.easysearch.custom.entity.Product;
import org.dromara.easyes.core.biz.EsPageInfo;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController {


    @GetMapping("/es/save")
    public R<?> save(@RequestParam String name, @RequestParam Double price){
        Product product = new Product(name, price);
        return R.success(EsUtils.getMapper(Product.class).insert(product));
    }

    @GetMapping("/es/get")
    public R<?> get(){
        EsPageInfo<Product> pageInfo = EsUtils.getMapper(Product.class).pageQuery(new LambdaEsQueryWrapper<>(), 1, 10);
        return R.success(pageInfo);
    }
}
